﻿using System;
using UniRx.InternalUtil;

namespace UniRx.Operators
{
	// Token: 0x02000302 RID: 770
	internal class SkipUntilObservable<T, TOther> : OperatorObservableBase<T>
	{
		// Token: 0x0600103C RID: 4156 RVA: 0x0004B27C File Offset: 0x0004967C
		public SkipUntilObservable(IObservable<T> source, IObservable<TOther> other) : base(source.IsRequiredSubscribeOnCurrentThread<T>() || other.IsRequiredSubscribeOnCurrentThread<TOther>())
		{
			this.source = source;
			this.other = other;
		}

		// Token: 0x0600103D RID: 4157 RVA: 0x0004B2A6 File Offset: 0x000496A6
		protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
		{
			return new SkipUntilObservable<T, TOther>.SkipUntilOuterObserver(this, observer, cancel).Run();
		}

		// Token: 0x04000986 RID: 2438
		private readonly IObservable<T> source;

		// Token: 0x04000987 RID: 2439
		private readonly IObservable<TOther> other;

		// Token: 0x02000303 RID: 771
		private class SkipUntilOuterObserver : OperatorObserverBase<T, T>
		{
			// Token: 0x0600103E RID: 4158 RVA: 0x0004B2B5 File Offset: 0x000496B5
			public SkipUntilOuterObserver(SkipUntilObservable<T, TOther> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x0600103F RID: 4159 RVA: 0x0004B2C8 File Offset: 0x000496C8
			public IDisposable Run()
			{
				SingleAssignmentDisposable singleAssignmentDisposable = new SingleAssignmentDisposable();
				SkipUntilObservable<T, TOther>.SkipUntilOuterObserver.SkipUntil skipUntil = new SkipUntilObservable<T, TOther>.SkipUntilOuterObserver.SkipUntil(this, singleAssignmentDisposable);
				SingleAssignmentDisposable singleAssignmentDisposable2 = new SingleAssignmentDisposable();
				SkipUntilObservable<T, TOther>.SkipUntilOuterObserver.SkipUntilOther observer = new SkipUntilObservable<T, TOther>.SkipUntilOuterObserver.SkipUntilOther(this, skipUntil, singleAssignmentDisposable2);
				singleAssignmentDisposable.Disposable = this.parent.source.Subscribe(skipUntil);
				singleAssignmentDisposable2.Disposable = this.parent.other.Subscribe(observer);
				return StableCompositeDisposable.Create(singleAssignmentDisposable2, singleAssignmentDisposable);
			}

			// Token: 0x06001040 RID: 4160 RVA: 0x0004B327 File Offset: 0x00049727
			public override void OnNext(T value)
			{
			}

			// Token: 0x06001041 RID: 4161 RVA: 0x0004B329 File Offset: 0x00049729
			public override void OnError(Exception error)
			{
			}

			// Token: 0x06001042 RID: 4162 RVA: 0x0004B32B File Offset: 0x0004972B
			public override void OnCompleted()
			{
			}

			// Token: 0x04000988 RID: 2440
			private readonly SkipUntilObservable<T, TOther> parent;

			// Token: 0x02000304 RID: 772
			private class SkipUntil : IObserver<T>
			{
				// Token: 0x06001043 RID: 4163 RVA: 0x0004B32D File Offset: 0x0004972D
				public SkipUntil(SkipUntilObservable<T, TOther>.SkipUntilOuterObserver parent, IDisposable subscription)
				{
					this.parent = parent;
					this.observer = EmptyObserver<T>.Instance;
					this.subscription = subscription;
				}

				// Token: 0x06001044 RID: 4164 RVA: 0x0004B350 File Offset: 0x00049750
				public void OnNext(T value)
				{
					this.observer.OnNext(value);
				}

				// Token: 0x06001045 RID: 4165 RVA: 0x0004B360 File Offset: 0x00049760
				public void OnError(Exception error)
				{
					try
					{
						this.observer.OnError(error);
					}
					finally
					{
						this.parent.Dispose();
					}
				}

				// Token: 0x06001046 RID: 4166 RVA: 0x0004B39C File Offset: 0x0004979C
				public void OnCompleted()
				{
					try
					{
						this.observer.OnCompleted();
					}
					finally
					{
						this.subscription.Dispose();
					}
				}

				// Token: 0x04000989 RID: 2441
				public volatile IObserver<T> observer;

				// Token: 0x0400098A RID: 2442
				private readonly SkipUntilObservable<T, TOther>.SkipUntilOuterObserver parent;

				// Token: 0x0400098B RID: 2443
				private readonly IDisposable subscription;
			}

			// Token: 0x02000305 RID: 773
			private class SkipUntilOther : IObserver<TOther>
			{
				// Token: 0x06001047 RID: 4167 RVA: 0x0004B3D8 File Offset: 0x000497D8
				public SkipUntilOther(SkipUntilObservable<T, TOther>.SkipUntilOuterObserver parent, SkipUntilObservable<T, TOther>.SkipUntilOuterObserver.SkipUntil sourceObserver, IDisposable subscription)
				{
					this.parent = parent;
					this.sourceObserver = sourceObserver;
					this.subscription = subscription;
				}

				// Token: 0x06001048 RID: 4168 RVA: 0x0004B3F5 File Offset: 0x000497F5
				public void OnNext(TOther value)
				{
					this.sourceObserver.observer = this.parent.observer;
					this.subscription.Dispose();
				}

				// Token: 0x06001049 RID: 4169 RVA: 0x0004B41C File Offset: 0x0004981C
				public void OnError(Exception error)
				{
					try
					{
						this.parent.observer.OnError(error);
					}
					finally
					{
						this.parent.Dispose();
					}
				}

				// Token: 0x0600104A RID: 4170 RVA: 0x0004B460 File Offset: 0x00049860
				public void OnCompleted()
				{
					this.subscription.Dispose();
				}

				// Token: 0x0400098C RID: 2444
				private readonly SkipUntilObservable<T, TOther>.SkipUntilOuterObserver parent;

				// Token: 0x0400098D RID: 2445
				private readonly SkipUntilObservable<T, TOther>.SkipUntilOuterObserver.SkipUntil sourceObserver;

				// Token: 0x0400098E RID: 2446
				private readonly IDisposable subscription;
			}
		}
	}
}
